| Conditions | 13 | 
| Paths | 13 | 
| Total Lines | 109 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 2 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like gaaf.js ➔ ... ➔ fillInAddress often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | jQuery(function ($) { | 
            ||
| 7 |     function fillInAddress() { | 
            ||
| 8 | var place = autocomplete.getPlace();  | 
            ||
| 9 | console.log(place);  | 
            ||
| 10 | var temp_state = '';  | 
            ||
| 11 | var street_number = '';  | 
            ||
| 12 | |||
| 13 |         for (var i = 0; i < place.address_components.length; i++) { | 
            ||
| 14 | |||
| 15 | var address_type = place.address_components[i].types[0];  | 
            ||
| 16 | |||
| 17 |             switch (address_type) { | 
            ||
| 18 | case 'street_number':  | 
            ||
| 19 | street_number = place.address_components[i]['short_name'];  | 
            ||
| 20 | break;  | 
            ||
| 21 | case 'route':  | 
            ||
| 22 | var val = place.address_components[i]['long_name'];  | 
            ||
| 23 |                     document.getElementById('wpinv_address').value = street_number ? street_number+" "+val : val; | 
            ||
| 24 | break;  | 
            ||
| 25 | case 'postal_town':  | 
            ||
| 26 | var val = place.address_components[i]['short_name'];  | 
            ||
| 27 |                     document.getElementById('wpinv_city').value = val; | 
            ||
| 28 | break;  | 
            ||
| 29 | case 'locality':  | 
            ||
| 30 | var val = place.address_components[i]['long_name'];  | 
            ||
| 31 |                     document.getElementById('wpinv_city').value = val; | 
            ||
| 32 | break;  | 
            ||
| 33 | case 'administrative_area_level_1':  | 
            ||
| 34 | var val = place.address_components[i]['short_name'];  | 
            ||
| 35 | temp_state = val;  | 
            ||
| 36 | break;  | 
            ||
| 37 | case 'country':  | 
            ||
| 38 | var val = place.address_components[i]['short_name'];  | 
            ||
| 39 | |||
| 40 |                     $('#wpinv_country').val(val); | 
            ||
| 41 | |||
| 42 |                     var elB = $('#wpinv-address'); | 
            ||
| 43 |                     var elF = $('#wpinv-fields'); | 
            ||
| 44 |                     data = { | 
            ||
| 45 | action: 'wpinv_get_states_field',  | 
            ||
| 46 | country: val,  | 
            ||
| 47 | field_name: 'wpinv_state',  | 
            ||
| 48 | };  | 
            ||
| 49 | |||
| 50 |                     if(elB.length){ | 
            ||
| 51 |                         var $this = $('#wpinv_country', elB); | 
            ||
| 52 | |||
| 53 |                         $this.closest('.gdmbx-row').find('.wpi-loader').show(); | 
            ||
| 54 |                         $('#wpinv_state', elB).css({ | 
            ||
| 55 | 'opacity': '.5'  | 
            ||
| 56 | });  | 
            ||
| 57 |                         $.post(ajaxurl, data, function(response) { | 
            ||
| 58 |                             if ('nostates' === response || '' == temp_state) { | 
            ||
| 59 | var text_field = '<input type="text" value="' + temp_state + '" id="wpinv_state" name="wpinv_state" />';  | 
            ||
| 60 |                                 $('#wpinv_state', elB).replaceWith(text_field); | 
            ||
| 61 |                             } else { | 
            ||
| 62 |                                 $('#wpinv_state', elB).replaceWith(response); | 
            ||
| 63 |                                 $('#wpinv_state', elB).find('option[value="' + temp_state + '"]').attr('selected', 'selected'); | 
            ||
| 64 |                                 $('#wpinv_state', elB).find('option[value=""]').remove(); | 
            ||
| 65 | }  | 
            ||
| 66 | |||
| 67 |                             $('#wpinv_state', elB).addClass('gdmbx2-text-large'); | 
            ||
| 68 |                             if (typeof $this.data('change') === '1') { | 
            ||
| 69 |                                 $('#wpinv_state', elB).change(); | 
            ||
| 70 |                             } else { | 
            ||
| 71 | window.wpiConfirmed = true;  | 
            ||
| 72 |                                 $('#wpinv-recalc-totals').click(); | 
            ||
| 73 | window.wpiConfirmed = false;  | 
            ||
| 74 | }  | 
            ||
| 75 | |||
| 76 |                             $this.closest('.gdmbx-row').find('.wpi-loader').hide(); | 
            ||
| 77 |                             $('#wpinv_state', elB).css({ | 
            ||
| 78 | 'opacity': '1'  | 
            ||
| 79 | });  | 
            ||
| 80 | });  | 
            ||
| 81 |                     } else if(elF.length){ | 
            ||
| 82 |                         $('.wpinv_errors').remove(); | 
            ||
| 83 |                         wpinvBlock(jQuery('#wpinv_state_box')); | 
            ||
| 84 |                         var $this = $('#wpinv_country', elF); | 
            ||
| 85 |                         $.post(ajaxurl, data, function(response) { | 
            ||
| 86 |                             if ('nostates' === response) { | 
            ||
| 87 | var text_field = '<input type="text" required="required" class="wpi-input required" id="wpinv_state" name="wpinv_state">';  | 
            ||
| 88 |                                 $('#wpinv_state', elF).replaceWith(text_field); | 
            ||
| 89 |                             } else { | 
            ||
| 90 |                                 $('#wpinv_state', elF).replaceWith(response); | 
            ||
| 91 |                                 $('#wpinv_state', elF).find('option[value="' + temp_state + '"]').attr('selected', 'selected'); | 
            ||
| 92 |                                 var changeState = function() { | 
            ||
| 93 | wpinv_recalculate_taxes(temp_state);  | 
            ||
| 94 | };  | 
            ||
| 95 |                                 $("#wpinv_state", elF).unbind("change", changeState); | 
            ||
| 96 |                                 $("#wpinv_state", elF).bind("change", changeState); | 
            ||
| 97 | }  | 
            ||
| 98 |                             $('#wpinv_state', elF).find('option[value=""]').remove(); | 
            ||
| 99 |                             $('#wpinv_state', elF).addClass('form-control wpi-input required'); | 
            ||
| 100 |                         }).done(function(data) { | 
            ||
| 101 |                             jQuery('#wpinv_state_box').unblock(); | 
            ||
| 102 | wpinv_recalculate_taxes();  | 
            ||
| 103 | });  | 
            ||
| 104 | }  | 
            ||
| 105 | |||
| 106 | break;  | 
            ||
| 107 | case 'postal_code':  | 
            ||
| 108 | var val = place.address_components[i]['short_name'];  | 
            ||
| 109 |                     document.getElementById('wpinv_zip').value = val; | 
            ||
| 110 | break;  | 
            ||
| 111 | default:  | 
            ||
| 112 | break;  | 
            ||
| 113 | }  | 
            ||
| 114 | }  | 
            ||
| 115 | }  | 
            ||
| 116 | });  | 
            
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.